package com.jieshen.lesson5;

import javax.swing.*;
import java.awt.*;
import java.net.MalformedURLException;
import java.net.URL;

import static org.jboss.weld.environment.deployment.WeldResourceLoader.getClassLoader;

public class ImageIconTest extends JFrame {
    public ImageIconTest() throws MalformedURLException {

        JLabel label = new JLabel("ImageIcon");
//        URL url = ImageIconTest.class.getResource("/2.jpg");
//        URL url = new URL("D:\\1_git\\Java\\Java_learn\\GUI\\AWT\\code\\lesson4\\src\\main\\resources\\img\\2.jpg");
//        ImageIcon imageIcon = new ImageIcon("2.jpg");
        URL url = getClassLoader().getResource("2.jpg");
//        ImageIcon imageIcon = new ImageIcon("D:\\1_git\\Java\\Java_learn\\GUI\\AWT\\code\\lesson4\\src\\main\\resources\\img\\2.jpg");
        ImageIcon imageIcon = new ImageIcon(url);
        label.setIcon(imageIcon);
        label.setHorizontalAlignment(SwingConstants.CENTER);
        Container container = getContentPane();
        container.add(label);
        setVisible(true);
        setBounds(100,100,500,500);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    public static void main(String[] args) throws MalformedURLException {
        new ImageIconTest();
    }
}
